package com.lv.service.adapter

import android.view.View
import android.widget.TextView
import androidx.constraintlayout.widget.ConstraintLayout
import com.blankj.utilcode.util.SizeUtils
import com.chad.library.adapter.base.BaseSectionQuickAdapter
import com.lv.common.base.DataBindBaseViewHolder
import com.lv.common.imp.OnPositionTListener
import com.lv.service.R
import com.lv.service.bean.TelSecondCategory
import com.lv.service.databinding.ItemCardCategoryBottomHeaderBinding
import com.lv.service.databinding.ItemCardCategoryImageBottomBinding

/**
 * 作者： ygx
 * 创建日期：2022/6/24 8:10 PM
 * 签名： 天行健，君子以自强不息；地势坤，君子以厚德载物。
 *      _              _           _     _   ____  _             _ _
 *     / \   _ __   __| |_ __ ___ (_) __| | / ___|| |_ _   _  __| (_) ___
 *    / _ \ | '_ \ / _` | '__/ _ \| |/ _` | \___ \| __| | | |/ _` | |/ _ \
 *   / ___ \| | | | (_| | | | (_) | | (_| |  ___) | |_| |_| | (_| | | (_) |
 *  /_/   \_\_| |_|\__,_|_|  \___/|_|\__,_| |____/ \__|\__,_|\__,_|_|\___/
 *
 * You never know what you can do until you try !
 * ----------------------------------------------------------------
 *
 */
class CardCategoryImageBottomAdapter(private val datas: MutableList<TelSecondCategory>?) :
    BaseSectionQuickAdapter<TelSecondCategory, DataBindBaseViewHolder>(
        R.layout.item_card_category_bottom_header, R.layout.item_card_category_image_bottom, datas
    ) {
    override fun convert(
        holder: DataBindBaseViewHolder, item: TelSecondCategory, payloads: List<Any>
    ) {
        super.convert(holder, item, payloads)
        val mBinding: ItemCardCategoryImageBottomBinding =
            holder.getBind() as ItemCardCategoryImageBottomBinding
        mBinding.ivImageTag.visibility = if (item.isSelcted) View.VISIBLE else View.GONE

    }

    override fun convert(holder: DataBindBaseViewHolder, item: TelSecondCategory) {
        val mBinding: ItemCardCategoryImageBottomBinding =
            holder.getBind() as ItemCardCategoryImageBottomBinding
        mBinding.itemRoot = item
//        //防止列表闪烁
        mBinding.executePendingBindings()
        val layoutPosition = holder.layoutPosition
//        val clParent: ConstraintLayout = helper.getView<ConstraintLayout>(R.id.cl_containers)
//        val tvContent = helper.getView<TextView>(R.id.tv_content)
//        val viewTag = helper.getView<View>(R.id.view_tag)
//        tvContent.paint.isFakeBoldText = true
//        tvContent.textSize = if (item.isSelcted) 14.0f else 13.0f
        mBinding.clContainers.setOnClickListener {
            onViewItemClickListener?.onClick(layoutPosition, item)
        }
//        val layoutParams = clParent.layoutParams as RecyclerView.LayoutParams
//        if (layoutPosition == 0) {
//            layoutParams.topMargin = SizeUtils.dp2px(14.0f)
//        } else {
//            layoutParams.topMargin = SizeUtils.dp2px(12.0f)
//        }
//        clParent.layoutParams = layoutParams
//        clParent.setOnClickListener { onViewItemClickListener?.onClick(layoutPosition, item) }

    }

    var onViewItemClickListener: OnPositionTListener<TelSecondCategory>? = null
    override fun convertHeader(helper: DataBindBaseViewHolder, item: TelSecondCategory) {
        val mBinding: ItemCardCategoryBottomHeaderBinding =
            helper.getBind() as ItemCardCategoryBottomHeaderBinding
        mBinding.itemRoot = item.name
//        //防止列表闪烁
        mBinding.executePendingBindings()
        val tvContent = helper.getView<TextView>(R.id.tv_content)

        val layoutPosition = helper.layoutPosition
        val layoutParams = tvContent.layoutParams as ConstraintLayout.LayoutParams
        if (layoutPosition == 0) {
            layoutParams.topMargin = SizeUtils.dp2px(10.0f)
        } else {
            layoutParams.topMargin = SizeUtils.dp2px(17.0f)
        }
        tvContent.layoutParams = layoutParams

    }


}